package top.maof.book.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import top.maof.book.model.Score;

@Mapper
public interface ScoreMapper extends BaseMapper<Score> {
    // 获取小说的评分
    @Select("select sum(score)/count(score) from score where book_id = #{bookId}")
    Double bookScore(@Param("bookId") int bookId);

    @Select("select id,user_id,book_id,score,time from score where book_id=#{bookId} and user_id = #{userId}")
    Score findScoreByUserAndBook(int userId, int bookId);

    @Insert("insert into score (id,user_id,book_id,score,time) " +
            "values (id,userId,bookId,score,time)")
    Integer add(Score s);


    @Update("update score set score = #{score},time = #{time} where book_id=#{bookId} and user_id = #{userId}")
    Integer updateScore(Score s);
}
